namespace CSharpPro._10_20_01;

public class demo
{
/*. 作业1、冒泡排序*/
//
    public void BubbleSort(int[] array)
    {
        if (array == null || array.Length <= 1) return;

        int n = array.Length;
        bool swapped;

        for (int i = 0; i < n - 1; i++)
        {
            swapped = false;
            for (int j = 0; j < n - i - 1; j++)
            {
                if (array[j] > array[j + 1])
                {
                    int temp = array[j];
                    array[j] = array[j + 1];
                    array[j + 1] = temp;
                    swapped = true;
                }
            }
            if (!swapped) break;
        }
    }
}
